package java8Builder;

import com.alibaba.fastjson.JSONObject;

import java.util.*;

public class GirlFriend {

    private String name;

    private int age;

    private List<String> hobby;

    private Map<String, String> gift;

    public void addHobby(String hobby){
        this.hobby = Optional.ofNullable(this.hobby).orElse(new ArrayList<>());
        this.hobby.add(hobby);
    }

    public void addGift(String day, String gift){
        this.gift = Optional.ofNullable(this.gift).orElse(new HashMap<>());
        this.gift.put(day, gift);
    }

    public void setName(String name) {
        this.name = name;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public int getAge() {
        return age;
    }

    public List<String> getHobby() {
        return hobby;
    }

    public Map<String, String> getGift() {
        return gift;
    }

    public static void main(String[] args) {
        GirlFriend girlFriend = Builder.of(GirlFriend::new)
                .with(GirlFriend::setName, "小美")
                .with(GirlFriend::setAge, 21)
                .with(GirlFriend::addHobby,"逛街")
                .with(GirlFriend::addHobby, "购物")
                .with(GirlFriend::addGift, "情人节礼物", "LBR 1912女王时代")
                .build();
        System.out.println(JSONObject.toJSONString(girlFriend));
    }

}
